Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittest for pkg/limayaml/default.yaml #2334

Merged
merged 5 commits into from
Jul 17, 2024

Conversation

afbjorklund
Copy link
Member

@afbjorklund afbjorklund commented May 10, 2024

Make sure that it is possible to parse default.yaml to the expected LimaYAML structure

Add some minor changes, to make the internal representation (before defaults) "pretty"

Left to do is to remove the default list of architectures, from the default cpuType list:

After that, the default YAML is simply images: [] - since that value is still mandatory.

images: null

With some additional default values and "omitempty", it also matches an empty template.

vmType: null
os: null
arch: null
images: []
cpus: null
memory: null
disk: null
mountType: null
mountInotify: null
additionalDisks: null
ssh:
  localPort: null
  loadDotSSHPubKeys: null
  forwardAgent: null
  forwardX11: null
  forwardX11Trusted: null
caCerts:
  removeDefaults: null
  files: null
  certs: null
upgradePackages: null
containerd:
  system: null
  user: null
cpuType: null
rosetta:
  enabled: null
  binfmt: null
timezone: null
firmware:
  legacyBIOS: null
audio:
  device: null
video:
  display: null
  vnc:
    display: null
networks: null
propagateProxyEnv: null
hostResolver:
  enabled: null
  ipv6: null
  hosts: null
guestInstallPrefix: null
plain: null

@afbjorklund
Copy link
Member Author

afbjorklund commented May 10, 2024

The unmarshal and marshal functions should probably be refactored into separate files.

pkg/limayaml/load.go

pkg/limayaml/limayaml_test.go

I used encoding/json for the test logging, just to avoid dependencies and whitespace...

{"images":null,"ssh":{},"firmware":{},"audio":{},"video":{"vnc":{}},"containerd":{},"hostResolver":{},"caCerts":{},"rosetta":{}}

(side note: it seems a bit confused, about marshalling arrays and maps - both objects?)


There is a bug in encoding/json, in that there is no empty value for struct... (go issue: 11939)

It doesn't matter here, just makes test log "chatty" (workaround is to replace empty with nil)

If it bothers anyone, we could have a RemoveDefaults to "undo" the effects of FillDefaults

The go-yaml encoder works though, it doesn't add empty structs like the json and the xml do.

@afbjorklund afbjorklund marked this pull request as draft May 12, 2024 10:19
@afbjorklund

This comment was marked as resolved.

@afbjorklund afbjorklund marked this pull request as ready for review May 22, 2024 18:02
@AkihiroSuda
Copy link
Member

Could you rebase and squash the commits?

AkihiroSuda
AkihiroSuda previously approved these changes Jul 2, 2024
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda added this to the v0.23.0 (tentative) milestone Jul 2, 2024
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
@jandubois jandubois merged commit 486b90b into lima-vm:master Jul 17, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants